



set more off 
cap log close 
clear all
set niceness 10 
set processor 4
set scheme s1color 

*** Paths ****
gl path1 = "/Users/Wei/Dropbox/Census"
gl path2 = "/Users/Wei/Dropbox/Fertility/Workingdata"
gl path3 = "/Users/Wei/Dropbox/Fertility/Results"
gl path4 = "/Users/Wei/Dropbox/Fertility/Figures"

log using "$path3/Macro_results.log", replace  

*** This do file generates Figure B1, B2, B3 and Table B1 ***

use "$path2/fines_use", clear 
recode year (1979/1984 = 1) (1985/1989 = 2) (1990/1995 = 3) (1995/1999 = 4)(2000/2005 = 5), gen(year_group)
tw line fine year if prov != 54, by(province) xtit(Year)
gr export "$path4/fig_b1.eps", replace 

collapse fine, by(prov year_group)
reshape wide fine, i(prov) j(year_group)
rename prov code
merge 1:m code using "$path2/china_label.dta"
drop if code == 0
replace ename = subinstr(ename," Sheng"," ",.) 
replace ename = subinstr(ename," Shi"," ",.) 
replace ename = subinstr(ename," Zhizhiqu"," ",.) 

spmap fine1 using "$path2/china_map.dta" ,id(id) clmethod(custom) fcolor(Blues2) ocolor(none..) ndfcolor(gs15)  clbreaks(0 1.5 2.5 3.5 4.5 5) legend(label(2 "< 1.5") label(6 "> 4.5") subtit("Penalty levels", size(vsmall)))
gr export "$path4/fig_b2a.eps",replace 
spmap fine2 using "$path2/china_map.dta" ,id(id) clmethod(custom)  fcolor(Blues2) ocolor(none..) ndfcolor(gs15)  clbreaks(0 1.5 2.5 3.5 4.5 5) legend(label(2 "< 1.5") label(6 "> 4.5") subtit("Penalty levels", size(vsmall)))
gr export "$path4/fig_b2b.eps",replace 
spmap fine3 using "$path2/china_map.dta" ,id(id) clmethod(custom)  fcolor(Blues2) ocolor(none..) ndfcolor(gs15)  clbreaks(0 1.5 2.5 3.5 4.5 5) legend(label(2 "< 1.5") label(6 "> 4.5") subtit("Penalty levels", size(vsmall)))
gr export "$path4/fig_b2c.eps",replace 
spmap fine4 using "$path2/china_map.dta" ,id(id) clmethod(custom)  fcolor(Blues2) ocolor(none..) ndfcolor(gs15)   clbreaks(0 1.5 2.5 3.5 4.5 5) legend(label(2 "< 1.5") label(6 "> 4.5") subtit("Penalty levels", size(vsmall)))
gr export "$path4/fig_b2d.eps",replace 
spmap fine5 using "$path2/china_map.dta" ,id(id) clmethod(custom)  fcolor(Blues2) ocolor(none..) ndfcolor(gs15) clbreaks(0 1.5 2.5 3.5 4.5 5) legend(label(2 "< 1.5") label(6  "> 4.5") subtit("Penalty levels", size(vsmall)))
gr export "$path4/fig_b2e.eps",replace 



use "$path2/60years", clear
drop if mi(prov)
merge 1:1 prov year using "$path2/fines_use", nogen 
replace fine = 0 if year <= 1979 & fine == . 
replace fine = . if year < 1978

xtset prov year 

egen cid = group(prov)
gen lnpic = ln(pic)
replace lnpic = 0 if lnpic == . & year <= 2000
gen lnmic = ln(mic)
replace lnmic = 0 if lnmic == . & year <= 2000
gen lnuic = ln(uic)
replace lnuic = 0 if lnuic == . & year <= 2000

gen lnpop = ln(pop)
gen lnpop_male = ln(pop)
gen lnpop_female = ln(pop)
gen lnpop_urban = ln(pop_urban)
gen lnpop_rural = ln(pop_rural)

gen lngdp_pc = ln(gdp/pop*10000)
gen lngdp1_pc = ln(gdp_1st/pop)
gen lngdp2_pc = ln(gdp_2nd/pop)
gen lngdp3_pc = ln(gdp_3rd/pop)

gen gdp1_share = gdp_1st/gdp
gen gdp2_share = gdp_2nd/gdp
gen gdp3_share = gdp_3rd/gdp

gen lngov_exp = ln(exp_gen)
 
gen lngov_admin = ln(exp_admin+1)
gen lngov_ag = ln(exp_ag+1)
gen lngov_cul = ln(exp_cul+1)
gen lngov_ss = ln(exp_ss+1)

replace lngov_ss = 0 if lngov_ss==. & year >= 1978
gen lnwage= ln(wage_total/worker_total)
gen lnwage_urban = ln(wage_urban/worker_urban)
gen lnwage_state = ln(wage_state/worker_state)

gen lnteacher_primary = ln(teacher_primary/pop)
gen lnteacher_second = ln(teacher_second/pop)
gen lnteacher_higher = ln(teacher_higher/pop)

gen lnemp = ln(emp+1)
gen lnemp_urban = ln(emp_urban +1)
gen lnemp_rural = ln(emp_rural +1)

gen lndibao = ln(dibao+1)
replace lndibao = 0 if year <= 1990 & lndibao == . 

gen treat = 1 if prov == 11 | prov == 13 | prov == 21 | prov == 31 | prov == 32 | prov == 33 | prov == 35 |prov == 41 | prov == 42 | prov == 43 |prov == 44 | prov == 45| prov == 46| prov == 53| prov == 64 | prov == 65
replace treat = 0 if mi(treat)


gen p_val = . 
local j = 1 

cap erase "$path3/tab_b1.xls"
cap erase "$path3/tab_b1.txt"
xtset prov year 

qui:{
foreach y_var of var  lnpop lnpop_urban lnpop_rural birth_rate death_rate  lnemp lnemp_urban lnemp_rural  lnwage lnwage_urban lnwage_state ///
lngdp_pc unem_rate unem_urban  lnpic lnmic lnuic lndibao lngov_exp lngov_admin lngov_ag lngov_cul lngov_ss ///
bed_per10k doc_per10k lnteacher_primary lnteacher_second lnteacher_higher{
gen `y_var'_1p = l1.`y_var'
gen `y_var'_2p = (l1.`y_var'+l2.`y_var')/2
gen `y_var'_3p = (l1.`y_var'+l2.`y_var' +l3.`y_var')/3

reghdfe fine `y_var'_1p , a(prov##c.year year) cluster(cid)
testparm `y_var'_1p 
replace p_val = `r(p)' in `j' 
local ++j 
outreg2 using "$path3/tab_b1.xls", adds(F-test, `r(F)',p-val, `r(p)')  // col 1

reghdfe fine `y_var'_2p, a(prov##c.year year) cluster(cid)
testparm `y_var'_2p
replace p_val = `r(p)' in `j' 
local ++j 
outreg2 using "$path3/tab_b1.xls", adds(F-test, `r(F)',p-val, `r(p)')  // col 2

reghdfe fine `y_var'_3p, a(prov##c.year year) cluster(cid)
testparm `y_var'_3p
replace p_val = `r(p)' in `j' 
local ++j 
outreg2 using "$path3/tab_b1.xls", adds(F-test, `r(F)',p-val, `r(p)')   // col 3


reghdfe d.fine d.(`y_var'), a(prov##c.year year) cluster(cid)
testparm d.(`y_var')
replace p_val = `r(p)' in `j' 
local ++j 
outreg2 using "$path3/tab_b1.xls", adds(F-test, `r(F)',p-val, `r(p)')  // col 4

cap drop `y_var'_1p `y_var'_2p `y_var'_3p
}
}

xtset prov year 

foreach y_var in  "lnpop lnpop_urban lnpop_rural" "birth_rate death_rate"  "lnemp lnemp_urban lnemp_rural"  "lnwage lnwage_urban lnwage_state" "lngdp_pc unem_rate unem_urban" ///
  "lnpic lnmic lnuic lndibao" "lngov_exp lngov_admin lngov_ag lngov_cul lngov_ss" ///
"bed_per10k doc_per10k" "lnteacher_primary lnteacher_second lnteacher_higher"{
reghdfe fine l1.(`y_var') , a(prov##c.year year) cluster(cid)
testparm l1.(`y_var')
replace p_val = `r(p)' in `j' 
local ++j 
outreg2 using "$path3/tab_b1.xls", adds(F-test, `r(F)',p-val, `r(p)')  // col 5

cap drop `y_var'_1p `y_var'_2p `y_var'_3p
}



hist p_val, kdens xtit("P-values") xline(0.1, lp(dash)) xline(0.05, lp(solid)) xlabel(0.05 0(0.1)1)
gr export "$path4/fig_b3.eps",replace 
su p_val, d

log close 
